package com.ruoyi.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.api.domain.Courier;
import com.ruoyi.api.mapper.CourierMapper;
import com.ruoyi.api.service.ICourierService;
import com.ruoyi.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 寻觅
 * @since 2025-06-13
 */
@Service
public class CourierServiceImpl extends ServiceImpl<CourierMapper, Courier> implements ICourierService {

    @Autowired
    CourierMapper courierMapper;

    @Override
    public List<Courier> listData(Integer companyId) {
        LambdaQueryWrapper<Courier> courierLambdaQueryWrapper = new LambdaQueryWrapper<>();
        courierLambdaQueryWrapper.eq(Courier::getCompanyId, companyId);
        return courierMapper.selectList(courierLambdaQueryWrapper);
    }

    @Override
    @Transactional
    public Integer addOrUp(Courier courier) {
        boolean saved = saveOrUpdate(courier);
        if (!saved) {
            throw new ServiceException("添加/修改失败", 201);
        }
        return courier.getCourierId();
    }


}
